Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is unique branch #79

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Is unique branch #79

wants to merge 3 commits into from

Conversation

Ada-11
Copy link

@Ada-11 Ada-11 commented Dec 23, 2020

Hi,
This is a solution of this exercise using JS obejcts.

P.S. Am I supposed to run the mocha tests in my machine?

THanks!

Ada-11 and others added 3 commits October 30, 2020 11:32
Another solution without additional data structures but using objects, with performance O(N).

function isUnique3(str){
let obj = {}
for( let elem of str){
  if(obj.hasOwnProperty(elem)) obj[elem]++
  else obj[elem]=1
}
for( key in obj){
  if (obj[key]=== 1) return true
  else return false
}
} 

isUnique3('ada') // false
isUnique3("golden") // true
Copy link
Contributor

@lhchavez lhchavez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

welcome!

This is a solution of this exercise using JS obejcts.

P.S. Am I supposed to run the mocha tests in my machine?

yes. that way you can quickly see if the algorithm as implemented solves the desired problem. in this case, the tests seem to not be passing, so it is likely that the solution is not correct :(

rather than returning an array, the function should return true if all characters in the string are unique or false otherwise (the name is a hint: isUnique is something that hints at a yes/no answer).

THanks!

Comment on lines +23 to +24
assert.equal(isUnique1("tech"), true);
assert.equal(isUnique2("tech"), true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert.equal(isUnique1("tech"), true);
assert.equal(isUnique2("tech"), true);
assert.equal(isUnique("tech"), true);

there's only one implementation in this file. same below.

@@ -1,3 +1,4 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like an unintended change in another person's file:

Suggested change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants